package com.seetaface.controller;

import com.seetaface.common.CommonResult;
import com.seetaface.pojo.FaceResultRequest;
import com.seetaface.service.SeetafaceService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource;
import java.io.IOException;

import static com.seetaface.common.CommonResult.success;

/**
 * @Author SUN
 * @Description
 * @Data 2023/3/28 14:12
 */
@Api(tags = "人脸识别API",produces = "http")
@RestController
@RequestMapping("/seetaface")
public class SeetafaceController {

    @Resource
    private SeetafaceService seetafaceService;


    @ApiOperation(value = "人脸注册",notes = "人脸注册")
    @PostMapping("/register")
    public CommonResult<FaceResultRequest> register(@RequestParam("key")String key, @RequestParam("faceImage") MultipartFile faceImage) throws IOException {
        Assert.notNull(faceImage, "上传人脸照片不能为空");
        return success(seetafaceService.register(key,faceImage.getBytes()));
    }

    @ApiOperation(value = "人脸识别",notes = "人脸识别")
    @PostMapping("/seach")
    public CommonResult<FaceResultRequest> seach(@RequestParam("faceImage") MultipartFile faceImage) throws IOException {
        Assert.notNull(faceImage, "上传人脸照片不能为空");
        return success(seetafaceService.seach(faceImage.getBytes()));
    }
}
